AssertJ

@VERO
Created Date · 2023년 02월 10일 05:02
Last Updated Date · 2023년 02월 10일 05:02

@assertThatCode

  • testing that no exception is thrown
  • 어떤 exception도 던지지 않는 코드를 테스트할 수 있다.
// standard style
assertThatNoException().isThrownBy(() -> System.out.println("OK"));
// BDD style
thenNoException().isThrownBy(() -> System.out.println("OK"));
  • 비슷하게 사용하기
// standard style
assertThatCode(() -> System.out.println("OK")).doesNotThrowAnyException();
// BDD style
thenCode(() -> System.out.println("OK")).doesNotThrowAnyException();

나는 주로 아래 방법을 사용한다.